package Kalah;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;

import javax.swing.JPanel;

public class KalahCenterPanel extends JPanel {
	private static KalahCenterPanel m_ref;
	private ArrayList<HoleGfx> m_topHoles;
	private ArrayList<HoleGfx> m_botHoles;

	public static KalahCenterPanel getInstance() {
		if (m_ref == null)
			m_ref = new KalahCenterPanel();
		return m_ref;
	}

	private KalahCenterPanel() {
		setSize(500, 350); // MAGIC NUMBERS
		setVisible(true);
		m_topHoles = new ArrayList<HoleGfx>();
		m_botHoles = new ArrayList<HoleGfx>();
		for (int i = 0; i < Defines.NUM_OF_HOLES_PER_PLAYER; ++i) {
			if(i == 0){
				Shape circle = new Ellipse2D.Float(
						Defines.HOLES_START_X + Defines.HOLE_WIDTH  * i, 
						Defines.HOLES_START_Y, Defines.HOLE_WIDTH,Defines.HOLE_HEIGHT); 
				m_topHoles.add(new HoleGfx(circle, i, true));
	
			}
			else{
				Shape box = new Rectangle2D.Float(Defines.HOLES_START_X + Defines.HOLE_WIDTH  * i, 
						Defines.HOLES_START_Y, Defines.HOLE_WIDTH,Defines.HOLE_HEIGHT); 
				m_topHoles.add(new HoleGfx(box, i, true));
			}
		}
		for (int i = 0; i < Defines.NUM_OF_HOLES_PER_PLAYER; i++) {
			if(i == 6){
				Shape circle = new Ellipse2D.Float(
						Defines.HOLES_START_X + Defines.HOLE_WIDTH  * i, 
						Defines.HOLES_START_Y+Defines.HOLE_HEIGHT+Defines.HOLES_SPACER, Defines.HOLE_WIDTH,Defines.HOLE_HEIGHT); 
				m_topHoles.add(new HoleGfx(circle, i, true));
	
			}
			else{
				Shape box = new Rectangle2D.Float(	Defines.HOLES_START_X + Defines.HOLE_WIDTH  * i, 
						Defines.HOLES_START_Y+Defines.HOLE_HEIGHT+Defines.HOLES_SPACER, Defines.HOLE_WIDTH,Defines.HOLE_HEIGHT);
				m_topHoles.add(new HoleGfx(box, i, true));
			}
		}
	}

	public void paint(Graphics g) {
//		Shape circle = new Ellipse2D.Float(100.0f, 100.0f, 100.0f, 100.0f);
//		Shape square = new Rectangle2D.Double(100, 100,100, 100);
		Graphics2D ga = (Graphics2D)g;
//		//ga.draw(circle);
//		ga.setPaint(Color.green);
//		ga.fill(circle);
//		
//		ga.setPaint(Color.red);
//		ga.draw(square);
		
		// show holes
		ga.setPaint(Color.black);
		 for (HoleGfx top : m_topHoles){
			 ga.draw(top.getShape());
		 }
			 
		// for (Rectangle bot : m_botRects)
		// g.drawRect(bot.x, bot.y, bot.width, bot.height);
		// show pots

	}

	public class HoleGfx {
		// private m_circle;
		private Shape m_shape;
		private int m_holeNumber;
		private boolean m_isTop;

		public HoleGfx(Shape shape, int holeNumber, boolean isTop) {
			m_shape = shape;
			m_holeNumber = holeNumber;
			m_isTop = isTop;
		}

		public Shape getShape() {
			return m_shape;
		}

		public int getHole() {
			return m_holeNumber;
		}

		public boolean isTop() {
			return m_isTop;
		}

	}
}